package com.cysd.ewmksbs.ui.fragment

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.cszy.ewmxns.base.BaseVMFragment
import com.cszy.ewmxns.ext.launch
import com.cysd.ewmksbs.ksb_adapter.indexListAdapter
import com.cysd.ewmksbs.ui.activity.Ksb_DetailActivity1
import com.cysd.ewmksbs.ui.activity.Ksb_DetailActivity3
import com.cysd.ewmksbs.ui.activity.Ksb_DetailActivity4
import com.cysd.ewmksbs.viewmodel.IndexViewModel
import com.csylhl.ewmksb.databinding.FragmentQuestionBinding
import com.hlyj.http.ad.NewGroMoreFeedAdManager
import com.hnyyac.ad.mds.IAdView
import com.hnyyac.ad.mds.IAdViewListener
import com.hnyyac.ad.mds.manager.AdManager
import com.hnyyac.ad.mds.manager.AdManager.AdLoadListener
import com.hnyyac.ad.mds.utils.BaseAdConstants

class Ksb_QuestionFragment : BaseVMFragment<IndexViewModel, FragmentQuestionBinding>() ,IAdViewListener{

    private var adapter_list: indexListAdapter? = null
    private var newGromoreFeedAd: NewGroMoreFeedAdManager? = null

    override fun initView(savedInstanceState: Bundle?) {
        initRv()
        initAd()
    }

    private fun initAd() {
        AdManager.loadChapin_nocache(
            requireActivity(),
            101,
            this,
            object : AdLoadListener {
                override fun onAdLoadFailed(ad: IAdView?) {

                }
            })

        newGromoreFeedAd = NewGroMoreFeedAdManager(requireActivity(), BaseAdConstants.FEEDAD_Id, mBinding?.feedContainer,102)
        newGromoreFeedAd?.loadAd()
    }

    private fun initRv() {
        adapter_list = indexListAdapter()
        mBinding.rv.layoutManager = LinearLayoutManager(requireContext())
        mBinding.rv.adapter = adapter_list
        adapter_list?.submitList(mViewModel.getIndexList())
        //黑名单下 列表点击监听
        adapter_list?.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0, 1 -> {
                    Ksb_DetailActivity1.launch(requireContext(), position.toString())
                }

                2 -> {
                    launch(Ksb_DetailActivity3::class.java)
                }

                3 -> {
                    launch(Ksb_DetailActivity4::class.java)
                }
            }
        }
    }

    override fun onTrigger(adView: IAdView) {

    }

    override fun onAdShow(adView: IAdView) {

    }

    override fun onAdClick(adView: IAdView) {

    }

    override fun onAdClose(adView: IAdView) {

    }

    override fun onError(msg: String) {

    }

    override fun onLoadError(adView: IAdView) {

    }

    override fun onSuccess(adView: IAdView) {

    }

    override fun onLoad(adView: IAdView) {

    }

    override fun onSkipped() {

    }

    override fun onNoAd() {

    }

    override fun onTimeOut() {

    }
}